var zTree1;
var setting;
setting = {
		async: true,
		asyncUrl: getUrl,
		asyncDataFilter:dataFilter,
		isSimpleData: true,
		treeNodeKey: "menu_id",
		treeNodeParentKey: "parent_id",
		nameCol : "menu_name",
		fontCss: {color: "blue"},
		callback: {
			click: function(event, treeId, treeNode) {
				zTreeOnClick(event, treeId, treeNode);
			}
		}
	};

function dataFilter(id, node, data) {
	for(var i=0; i<data.length; i++) {
		data[i].isParent=true;
	}
	return data;
}

function showMenu(idName) {
	var obj = $("#" + idName);
	var offset = $("#" + idName).offset();
	$("#DropdownMenuBackground").css({left:offset.left + "px", top:offset.top + obj.outerHeight() + "px"}).slideDown("fast");
}
function hideMenu() {
	$("#DropdownMenuBackground").fadeOut("fast");
}

function getUrl(node) {
	if(node && node.menu_id) {
		return '../menu/listMenuAsJsonArray.action?menu.parent_id='+node.menu_id+'&menu.system_code='+$('#system_code').val();
	}
}

function reloadTree(parent_id) {
	$.ajax({
		url: '../menu/listMenuAsJsonArray.action',   
		type:'POST',   
		dataType: 'json',   
		data:"menu.parent_id="+parent_id+'&menu.system_code='+$('#system_code').val(),   
		beforeSend:function(xmlhttprequest){
		},
		success:function(data){
			hideMenu();
//			var results = data.results;
			zTree1 = $("#dropdownMenu").zTree(setting, clone(data));
		},
		error:function(action, errortype, desc){
			alert("加载菜单信息失败，请检查网络连接或稍后再试！");
		}
	});
}
